package com.minidao.framework.dao;

import java.io.Serializable;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class MiniSupportDao implements IMiniSupportDao {

	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Resource(name = "sessionFactory")
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	protected Session getSession() {
		return this.sessionFactory.getCurrentSession();
	}

	@Override
	public <T> void save(T t) {
		this.getSession().save(t);
	}

	@Override
	public <T> void update(T t) {
		this.getSession().update(t);
	}

	@Override
	public <T> void delete(T t) {
		this.getSession().delete(t);
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> T getById(Class<T> entityClass, Serializable id) {
		return (T) this.getSession().get(entityClass, id);
	}

}
